package com.tanhua.app.controller;

import com.tanhua.app.Service.MessagesService;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    //GET/messages/userinfo
    //根据环信id查询用户详细信息
    @GetMapping("/userinfo")
    public ResponseEntity findUserinfo(String huanxinId) {
        UserInfoVo vo = messagesService.findUserinfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    //POST/messages/contacts
    //添加联系人
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map) {
        Long userId = Long.parseLong(map.get("userId").toString());
        messagesService.contacts(userId);
        return ResponseEntity.ok(null);
    }

    //GET/messages/contacts
    //联系人列表
    @GetMapping("/contacts")
    public ResponseEntity contactsList(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String keyword) {
        PageResult pr = messagesService.contactsList(page, pagesize, keyword);
        return ResponseEntity.ok(pr);
    }
}
